﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ManagedThreadId
{
    class DoTheTest
    {
        private Thread Th { get; set; }

        public DoTheTest()
        {
            Th = new Thread(ThFun);
            Th.IsBackground = true;

            Th.Start();
        }

        public void Outside()
        {
            if (Thread.CurrentThread.ManagedThreadId == Th.ManagedThreadId)
                Console.WriteLine("OUTSIDE: equal");
            else
                Console.WriteLine("OUTSIDE: NOT equal");
        }

        private void ThFun()
        {
            while (true)
            {
                if (Thread.CurrentThread.ManagedThreadId == Th.ManagedThreadId)
                    Console.WriteLine("INSIDE: equal");
                else
                    Console.WriteLine("INSIDE: NOT equal");

                Thread.Sleep(3000);
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            DoTheTest dtt = new DoTheTest();

            while (true)
            {
                dtt.Outside();
                Thread.Sleep(3000);
            }
        }
    }
}
